package cn.com.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTCreationException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: yue
 * Date: 2018-03-27
 * Time: 22:25
 * Description:
 */
public class Test {
    public static void main(String[] args) {

    }
}

class apple{
    private Integer id;
    private color c;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @JSONField(serialize = false)
    public color getC() {
        return c;
    }

    @JSONField(deserialize = false)
    public void setC(color c) {
        this.c = c;
    }
    @JSONField(name = "c")
    public Integer getColor(){
        return c.getValue();
    }
    @JSONField(name = "c")
    public void setColor(Integer c){
        this.c=color.getEnum(c);
    }

    @Override
    public String toString() {
        return "apple{" +
                "id=" + id +
                ", c=" + c +
                '}';
    }

    public static void main(String[] args) {
        String token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7ImVtYWlsIjoiIiwidW5pb25pZCI6InVuc2FtcGxlMjM0NDU5MyIsImlkIjoiNWFiYjkwMzg4MTcyYmEwMDAxMzFiMDVlIiwiY2xpZW50SWQiOiI1YTk3ZWRlNmY4NjM1YTAwMDE4NTUxYTEifSwiZXhwIjoxNTIzNTM3NTkyfQ.s_ZqDx4-UBwY0Hd2zG5qe304azOMR8izu94SoIwOsYw";
        try {
            Algorithm algorithm = Algorithm.HMAC256("salt_authing_root");
            JWTVerifier verifier = JWT.require(algorithm)
                    .build(); //Reusable verifier instance
            DecodedJWT jwt = verifier.verify(token);
        } catch (UnsupportedEncodingException exception){
            //UTF-8 encoding not supported
            System.out.println("unsupport");
        } catch (JWTVerificationException exception){
            //Invalid signature/claims
            exception.printStackTrace();
        }

    }
}
enum color{
    RED(0),
    GREEN(1);
    private Integer value;
    private color(Integer value){
        this.value=value;
    }

    public Integer getValue() {
        return value;
    }

    public static color getEnum(Integer value){
        for (color c:color.values()){
            if (value.equals(c.value)){
                return c;
            }
        }
        return null;
    }
}